import Network
import SwiftUI

@Observable final class NetworkMonitor {
    private var monitor: NWPathMonitor
    private var queue: DispatchQueue

    var isConnected: Bool = false

    init() {
        self.monitor = NWPathMonitor()
        self.queue = DispatchQueue(label: "NetworkMonitor")

        self.monitor.pathUpdateHandler = { path in
            DispatchQueue.main.async {
                self.isConnected = path.status == .satisfied
            }
        }
        self.monitor.start(queue: self.queue)
    }
}
